#include <iostream>
#include <unistd.h>
using namespace std;


class Time {
private:
    int hour, min, sec;

public:
    Time();
    void Reset(int hour, int min, int sec);
    void ShowTime();
    Time operator-(Time t);
};

class MasterClock {
private:
    time_t systemTime;

public:
    MasterClock() = default;
    void SetTimeObject(Time* t);
};

class StopWatch {
private:
    Time begin, finish, elapsed;

public:
    StopWatch() = default;
    void Start();
    void Stop();
    void ReportTime();
};

// 田径教练
class TrackCoach {
public:
    StopWatch watch;
    void YelloOutTime();
};

int main() {
    TrackCoach john;
    john.watch.Start();

    srand(time(NULL));
    sleep(rand() % 5 + 2);

    john.watch.Stop();
    john.YelloOutTime();
}

Time::Time() {
    hour = min = 0;
    sec = 1;
}

void Time::Reset(int hour, int min, int sec) {
    this->hour = hour;
    this->min = min;
    this->sec = sec;
}

void Time::ShowTime() {
    cout << hour << ":" << min << ":" << sec << "\n";
}

Time Time::operator-(Time t) {
    Time r;
    r.Reset(hour-t.hour, min-t.min, sec-t.sec);
    if (r.sec < 0) {
        r.sec += 60;
        r.min--;
    }
    if (r.min < 0) {
        r.min += 60;
        r.hour--;
    }
    if (r.hour < 0) {
        r.hour += 24;
    }
    return r;
}

void MasterClock::SetTimeObject(Time* t) {
    time(&systemTime);
    tm* tm = localtime(&systemTime);
    t->Reset(tm->tm_hour, tm->tm_min, tm->tm_sec);
}

void StopWatch::Start() {
    MasterClock clock;
    clock.SetTimeObject(&begin);

    cout << "开始时间为: ";
    begin.ShowTime();
}

void StopWatch::Stop() {
    MasterClock clock;
    clock.SetTimeObject(&finish);

    cout << "结束时间为: ";
    finish.ShowTime();

    elapsed = finish - begin;
}

void StopWatch::ReportTime() {
    elapsed.ShowTime();
}

void TrackCoach::YelloOutTime() {
    cout << "所用时间为: ";
    watch.ReportTime();
}